﻿package mortal.game.view.copy.uniqueBoss
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import com.greensock.*;
    import extend.language.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.common.guide.stepOperater.*;
    import mortal.game.view.common.guide.view.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.uniqueBoss.view.*;
    import mortal.mvc.core.*;

    public class UniqueBossController extends CopyControllerBase
    {
        private var _isOpen:Boolean;
        private var _isGuide:Boolean;
        private var _funcPanel:AutoGuideNewFunc;
        private var _flyEffectSteper:AutoGuideFlyEffectSteper;

        public function UniqueBossController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.UniqueBossInfoUpdate, this.onBossInfoUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.UniqueBossResultInfo, this.onResultHandler);
            Dispatcher.addEventListener(EventName.UniqueBossEnterCopy, this.onEnterUniqueBossHandler);
            Dispatcher.addEventListener(EventName.NavbarButtonUIRowInited, this.ontInitIcon);
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.onLevelUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.NewDayUpdate, this.onDateChange);
            return;
        }// end function

        override public function enterCopy(param1:TCopy) : void
        {
            if (UniqueBossMainWin.isViewShow)
            {
                UniqueBossMainWin.instance.hide();
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskShowHideTrackExceptBtn, false));
            return;
        }// end function

        override public function leaveCopy() : void
        {
            super.leaveCopy();
            if (UniqueBossTimePanel.isViewShow)
            {
                UniqueBossTimePanel.instance.hide();
            }
            return;
        }// end function

        private function onEnterUniqueBossHandler(event:DataEvent) : void
        {
            if (UniqueBossUtil.getLeftTime() > 0)
            {
                CopyUtil.copyCheck(this.enterUniqueBossCopy);
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(40966));
            }
            return;
        }// end function

        private function enterUniqueBossCopy() : void
        {
            GameProxy.copy.enterCopy(GameConst.UniqueBossCopyCode);
            return;
        }// end function

        private function onBossInfoUpdateHandler(param1:Object) : void
        {
            UniqueBossTimePanel.instance.show();
            UniqueBossTimePanel.instance.data = param1 as SUniqueBossCopyInfoMsg;
            return;
        }// end function

        private function onResultHandler(param1:Object) : void
        {
            UniqueBossResultWin.instance.show();
            return;
        }// end function

        private function onLevelUpdateHandler(param1:Object) : void
        {
            this.onShowIconHandler();
            this.onShowGuideWin();
            return;
        }// end function

        private function ontInitIcon(event:DataEvent) : void
        {
            var _loc_2:* = cache.role.entityInfo.level;
            var _loc_3:* = UniqueBossUtil.getShowTime();
            if (_loc_2 >= GameConst.UniqueBossEnterLevel && _loc_3 > 0)
            {
                UniqueBossIcon.instance.show();
                this._isOpen = true;
                this._isGuide = true;
            }
            return;
        }// end function

        private function onShowIconHandler() : void
        {
            var _loc_1:* = cache.role.entityInfo.level;
            var _loc_2:* = UniqueBossUtil.getShowTime();
            if (_loc_1 >= GameConst.UniqueBossEnterLevel && _loc_2 > 0)
            {
                if (!this._isOpen)
                {
                    UniqueBossIcon.instance.show();
                    this._isOpen = true;
                }
            }
            else if (UniqueBossIcon.isViewShow())
            {
                UniqueBossIcon.instance.hide();
            }
            return;
        }// end function

        private function onShowGuideWin() : void
        {
            var _loc_1:* = cache.role.entityInfo.level;
            var _loc_2:* = ClockManager.instance.serverOpenDateNum;
            if (!(_loc_1 >= GameConst.UniqueBossEnterLevel && _loc_2 <= 4 && !this._isGuide))
            {
                return;
            }
            this._isGuide = true;
            if (this._funcPanel == null)
            {
                this._funcPanel = new AutoGuideNewFunc();
            }
            this._funcPanel.show();
            var _loc_4:Number = 0.1;
            this._funcPanel.scaleY = 0.1;
            this._funcPanel.scaleX = _loc_4;
            var _loc_3:* = FuncPreCofonfig.instance.getConfigBySystem("120");
            if (_loc_3 == null)
            {
                return;
            }
            this._funcPanel.setLabel("zuo_uniqueBoss_txt.png", "zuo_uniqueBoss.jpg", Language.getString(40967));
            this._funcPanel.setLabelPos(44 - 50, 88);
            this._funcPanel.callback = this.callEnd;
            this._funcPanel.x = 0;
            TweenMax.to(this._funcPanel, 0.1, {scaleX:1, scaleY:1, x:Global.stage.stageWidth / 2 - 260});
            return;
        }// end function

        private function callEnd() : void
        {
            this._funcPanel = null;
            if (this._flyEffectSteper == null)
            {
                this._flyEffectSteper = new AutoGuideFlyEffectSteper();
            }
            var _loc_1:* = new AutoGuideData();
            _loc_1.guideType = AutoGuideType.FlyEffect;
            _loc_1.guideTypeValue = "actionIconLayer;UniqueBossIcon";
            _loc_1.guideActivedType = "pre";
            _loc_1.guideActivedTypeValue = 1;
            this._flyEffectSteper.endCallback = this.callEnd2;
            this._flyEffectSteper.guide(_loc_1);
            return;
        }// end function

        private function callEnd2() : void
        {
            this._flyEffectSteper = null;
            UniqueBossMainWin.instance.show();
            return;
        }// end function

        private function onDateChange(param1:Object) : void
        {
            this.onShowIconHandler();
            return;
        }// end function

    }
}
